﻿var result1 = test1();
var result2 = test2();
Console.WriteLine(result1);
Console.WriteLine(result2);
Console.WriteLine(result1 == result2);

double test2()
{
    return new Digit(2.4);
}
Digit test1()
{
    return 2.4;
}

internal class Digit
{
    private double val;

    public Digit(double d)
    {
        val = d;
    }

    public static implicit operator double(Digit d)
    {
        return d.val;
    }

    public static implicit operator Digit(double d)
    {
        return new Digit(d);
    }
}

//static implicit operator 隐式转换目标类型(源类型)
//你被要求传入你定义的"隐式转换目标类型"时你可以传入"源类型"
//这时候编译器会给你调用一下你定义的那个方法